/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.beans;

import br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.HelpIndexer;
import br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.HelpSearcher;
import br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.entities.SearchResult;
import br.cesupa.fabsoft.nomedoprojeto.modules.systemmodule.beans.SessionBean;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Breno Leite
 */
public class HelpSearchResultBean {

    private HelpSearcher helpSearcher = new HelpSearcher();
    private HelpIndexer helpIndexer = new HelpIndexer();
    private String searchTime;
    private List<SearchResult> searchResults = new ArrayList<SearchResult>();

    public HelpSearchResultBean() {
        helpIndexer.indexDefaltDirectory();
        processQuery();
    }

    public int getSearchResultsLength() {
        return searchResults.size();
    }

    private void processQuery() {
        long startTime = System.currentTimeMillis();
        if (SessionBean.getCurrentInstance().getSearchQuery() != null) {
            getSearchResults().addAll(helpSearcher.search(
                    SessionBean.getCurrentInstance().getSearchQuery()));
        }

        long endTime = System.currentTimeMillis();
        setSearchTime(Long.toString(endTime - startTime));
    }

    /**
     * @return the searchTime
     */
    public String getSearchTime() {
        return searchTime;
    }

    /**
     * @param searchTime the searchTime to set
     */
    public void setSearchTime(String searchTime) {
        this.searchTime = searchTime;
    }

    /**
     * @return the searchResults
     */
    public List<SearchResult> getSearchResults() {
        return searchResults;
    }
}